Plotting tilings with bokehΒΆ

from IPython import get_ipython
if get_ipython() is not None:
    get_ipython().run_line_magic('load_ext', 'autoreload')
    get_ipython().run_line_magic('autoreload', '2')
from bokeh.io import output_notebook, show
from bokeh.models import ColumnDataSource, Grid, LinearAxis, Patches, Plot
from tilings import utils as u
from tilings import base as b
import numpy as np
from myst_nb import glue
output_notebook()
Loading BokehJS ...
seed_t = u.get_seed()
def get_cds(t:b.Tiling)-> ColumnDataSource:
    coords = [list(p.exterior.coords) for p in t.polys]
    xs = [[p[0] for p in c] for c in coords]
    ys = [[p[1] for p in c] for c in coords]
    return ColumnDataSource({"xs":xs, "ys":ys})
plot = Plot(
    title=None, plot_width=300, plot_height=300,
    min_border=0, toolbar_location=None)

glyph = Patches(xs="xs", ys="ys", fill_color="#fb9a99", fill_alpha=0.1)
plot.add_glyph(get_cds(seed_t), glyph)

show(plot)
ts = [seed_t]
for i in range(30):
    ts = u.update_tilings(ts)
    print(i, len(ts))
    irreg = u.get_irreg(ts)
    if irreg is not None:
        print("irreg found")
        break
0 1
1 2
2 4
3 4
4 4
5 6
6 9
7 8
8 7
9 10
10 13
11 20
12 26
13 31
14 33
15 20
16 28
17 40
18 56
19 62
20 84
21 86
22 78
23 94
24 92
25 98
26 150
27 168
28 219
29 215
for t in ts:
    plot.add_glyph(get_cds(t), glyph)

show(plot)
from bokeh.layouts import column
from bokeh.models import ColumnDataSource, CustomJS, Slider
from bokeh.plotting import Figure, output_file, show

output_file("js_on_change.html")

x = [x*0.005 for x in range(0, 200)]
y = x

source = ColumnDataSource(data=dict(x=x, y=y))

plot = Figure(plot_width=400, plot_height=400)
plot.line('x', 'y', source=source, line_width=3, line_alpha=0.6)

callback = CustomJS(args=dict(source=source), code="""
    var data = source.data;
    var f = cb_obj.value
    var x = data['x']
    var y = data['y']
    for (var i = 0; i < x.length; i++) {
        y[i] = Math.pow(x[i], f)
    }
    source.change.emit();
""")

slider = Slider(start=0.1, end=4, value=1, step=.1, title="power")
slider.js_on_change('value', callback)

layout = column(slider, plot)

show(layout)